//
//  LGFollowDataSyptomCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/21.
//

#import "LGFollowDataGlucoseCell.h"

#define baseWidth     (Screen_W-viewPix(56))
#define dateWidth   viewPix(45)
#define itemWidth   (Screen_W-viewPix(56)-dateWidth)/7.0

@interface LGFollowDataGlucoseCell()
/**   */
@property (nonatomic , strong)UIView *shadowView;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIView *topLineView;
/**   */
@property (nonatomic , strong)UIView *lineView1;
/**   */
@property (nonatomic , strong)UIView *lineView2;
/**   */
@property (nonatomic , strong)UIView *lineView3;
/**   */
@property (nonatomic , strong)UIView *lineView4;
/**   */
@property (nonatomic , strong)UIView *lineView5;
/**   */
@property (nonatomic , strong)UIView *lineView6;
/**   */
@property (nonatomic , strong)UIView *lineView7;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UILabel *breakfast1;
/**   */
@property (nonatomic , strong)UILabel *breakfast2;
/**   */
@property (nonatomic , strong)UILabel *lunch1;
/**   */
@property (nonatomic , strong)UILabel *lunch2;
/**   */
@property (nonatomic , strong)UILabel *dinner1;
/**   */
@property (nonatomic , strong)UILabel *dinner2;
/**   */
@property (nonatomic , strong)UILabel *sleepLabel;
/**   */
@property (nonatomic , strong)NSDictionary *colorDic;
@end

@implementation LGFollowDataGlucoseCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.colorDic = @{@"0":@"#333333",@"1":@"#E53C39",@"2":@"#FF9704"};
        [self createSubView];
    }
    return  self;
}

-(void)setShowCorner:(BOOL)showCorner{
    _showCorner = showCorner;
    CGFloat bottom = (showCorner == YES)?-viewPix(10):0;
    [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.shadowView).offset(bottom);
    }];
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.dateLabel.text = dataDic[@"record_date"];
    //早餐前-空腹
    self.breakfast1.text = dataDic[@"a_fbg"];
    self.breakfast1.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"a_fbg_status"])]];
    //早饭后
    self.breakfast2.text = dataDic[@"a_pbg"];
    self.breakfast2.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"a_pbg_status"])]];
    //午饭前
    self.lunch1.text = dataDic[@"b_fbg"];
    self.lunch1.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"b_fbg_status"])]];
    //午饭后
    self.lunch2.text = dataDic[@"b_pbg"];
    self.lunch2.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"b_pbg_status"])]];
    //晚饭前
    self.dinner1.text = dataDic[@"c_fbg"];
    self.dinner1.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"c_fbg_status"])]];
    //晚饭后
    self.dinner2.text = dataDic[@"c_pbg"];
    self.dinner2.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"c_pbg_status"])]];
    //睡前
    self.sleepLabel.text = dataDic[@"d_fbg"];
    self.sleepLabel.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"d_fbg_status"])]];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.shadowView];
    [self.shadowView addSubview:self.baseView];
    [self.shadowView addSubview:self.topLineView];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.breakfast1];
    [self.baseView addSubview:self.breakfast2];
    [self.baseView addSubview:self.lunch1];
    [self.baseView addSubview:self.lunch2];
    [self.baseView addSubview:self.dinner1];
    [self.baseView addSubview:self.dinner2];
    [self.baseView addSubview:self.sleepLabel];
    [self.baseView addSubview:self.lineView1];
    [self.baseView addSubview:self.lineView2];
    [self.baseView addSubview:self.lineView3];
    [self.baseView addSubview:self.lineView4];
    [self.baseView addSubview:self.lineView5];
    [self.baseView addSubview:self.lineView6];
    [self.baseView addSubview:self.lineView7];
    [self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(-viewPix(5));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(viewPix(5));
    }];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.shadowView).offset(viewPix(12));
        make.right.equalTo(self.shadowView).offset(-viewPix(12));
        make.top.equalTo(self.shadowView);
        make.bottom.equalTo(self.shadowView).offset(0);
        make.height.equalTo(@(viewPix(40)));
    }];
    [self.topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.baseView);
        make.top.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.left.equalTo(self.baseView);
        make.width.equalTo(@(dateWidth));
    }];
    [self.breakfast1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.dateLabel.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.breakfast2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.breakfast1.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.lunch1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.breakfast2.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.lunch2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.lunch1.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.dinner1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.lunch2.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.dinner2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.dinner1.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.sleepLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.dinner2.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.dateLabel.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.breakfast1.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.breakfast2.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.lunch1.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.lunch2.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.dinner1.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.dinner2.mas_right);
        make.width.equalTo(@(0.5));
    }];
}
-(UIView *)shadowView{
    if(!_shadowView){
        _shadowView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _shadowView.backgroundColor = [UIColor whiteColor];
    }
    return _shadowView;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.layer.borderColor = [UIColor colorWithString:@"#E0E0E0"].CGColor;
        _baseView.layer.borderWidth = 1;
        _baseView.cornerRidus = 7;
    }
    return _baseView;
}
-(UIView *)topLineView{
    if(!_topLineView){
        _topLineView = [[UIView alloc] init];
        _topLineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _topLineView;
}
-(UIView *)lineView1{
    if(!_lineView1){
        _lineView1 = [[UIView alloc] init];
        _lineView1.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView1;
}

-(UIView *)lineView2{
    if(!_lineView2){
        _lineView2 = [[UIView alloc] init];
        _lineView2.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView2;
}

-(UIView *)lineView3{
    if(!_lineView3){
        _lineView3 = [[UIView alloc] init];
        _lineView3.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView3;
}

-(UIView *)lineView4{
    if(!_lineView4){
        _lineView4 = [[UIView alloc] init];
        _lineView4.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView4;
}

-(UIView *)lineView5{
    if(!_lineView5){
        _lineView5 = [[UIView alloc] init];
        _lineView5.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView5;
}

-(UIView *)lineView6{
    if(!_lineView6){
        _lineView6 = [[UIView alloc] init];
        _lineView6.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView6;
}

-(UIView *)lineView7{
    if(!_lineView7){
        _lineView7 = [[UIView alloc] init];
        _lineView7.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView7;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"日期" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _dateLabel;
}

-(UILabel *)breakfast1{
    if(!_breakfast1){
        _breakfast1 = [UILabel lableWithText:@"收缩压" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _breakfast1;
}

-(UILabel *)breakfast2{
    if(!_breakfast2){
        _breakfast2 = [UILabel lableWithText:@"舒张压" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _breakfast2;
}


-(UILabel *)lunch1{
    if(!_lunch1){
        _lunch1 = [UILabel lableWithText:@"收缩压" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _lunch1;
}

-(UILabel *)lunch2{
    if(!_lunch2){
        _lunch2 = [UILabel lableWithText:@"舒张压" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _lunch2;
}

-(UILabel *)dinner1{
    if(!_dinner1){
        _dinner1 = [UILabel lableWithText:@"收缩压" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _dinner1;
}

-(UILabel *)dinner2{
    if(!_dinner2){
        _dinner2 = [UILabel lableWithText:@"舒张压" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _dinner2;
}

-(UILabel *)sleepLabel{
    if(!_sleepLabel){
        _sleepLabel = [UILabel lableWithText:@"收缩压" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _sleepLabel;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
